<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>基本信息维护</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" type="text/css" href="../../css/style.css">
	<script type="text/javascript" src="../../js/jquery-1.8.2.js"></script>
	<script type="text/javascript" src="../../js/dialog/jquery.artDialog.source.js?skin=default"></script>
	<script type="text/javascript" src="../../js/dialog/plugins/iframeTools.source.js"></script>
	<script type="text/javascript" src="../../js/jquery.ztree.all-3.5.min.js"></script>
	<script type="text/javascript" src="../../js/datepicker/WdatePicker.js"></script>
	<script type="text/javascript" src="../../js/jquery.form.js"></script>
	<script type="text/javascript" src="../../js/jquery.page.js"></script>
	<script type="text/javascript" src="../../js/base.js"></script>
</head>
<body class="app">
	<h3>基本信息维护</h3>
	<form class="search" name="search">
		<div class="tbdiv">
		<table>
			<tr>
				<th>用途：</th>
				<td><select name="cardUse" style="width:75px;"></select></td>
				<th>设备号：</th>
				<td><input name="cardNumber" type="text" class="inputText" /></td>
				<td align="right"><input type="submit" class="inputButton" value="查询"/></td>
			</tr>
		</table>
		</div>
	</form>
	<div id="list"></div>
	<div class="optionlink">
		<span id="btnAdd">【添加信息】</span>
		<span id="btnDel">【删除所选】</span>
	</div>
	<div id="addview" style="width:650px;display:none;">
		<form id="addForm" name="addForm" action="jbxxwh_save.action" method="post">
		<dl class="view">
			<dt class="giant">设备号：</dt>
			<dd class="giant"><input type="text" class="inputText" style="width:150px" name="cardNumber" value="C" ver="/^[cC][0-9a-fA-F]{6,6}$/" msg="您输入的设备号不合法。" onchange="vCode(this)" /></dd>
			<dt class="giant">用途：</dt>
			<dd class="giant"><select name="cardUse" style="width:159px"></select></dd>
			<dt class="giant">设备版本：</dt>
			<dd class="giant"><input type="text" class="inputText" style="width:150px" name="cardEdition" /></dd>
			<dt class="giant">启用时间：</dt>
			<dd class="giant"><input type="text" class="inputText Wdate" style="width:156px;padding:0px;" name="cardUseDate" onfocus="WdatePicker()" readonly="readonly" /></dd>
			<dt class="giant">所属机构：</dt>
			<dd class="giant"><select name="agencyType" style="width:159px"></select></dd>
			<dt class="giant">所属单位：</dt>
			<dd class="giant"><select name="unitCode"><option value="">-请选择-</option></select></dd>
			<div class="cl"></div>
		</dl>
		</form>
	</div>
	<div id="updview" style="width:650px;display:none;">
		<form id="updForm" name="updForm" action="jbxxwh_save.action" method="post">
		<input type="hidden" name="indexId" />
		<dl class="view">
			<dt class="giant">设备号：</dt>
			<dd class="giant"><label name="cardNumber"></label><input type="hidden" name="cardNumber"/></dd>
			<dt class="giant">用途：</dt>
			<dd class="giant"><select name="cardUse" style="width:159px"></select></dd>
			<dt class="giant">设备版本：</dt>
			<dd class="giant"><input type="text" class="inputText" style="width:150px" name="cardEdition" /></dd>
			<dt class="giant">启用时间：</dt>
			<dd class="giant"><label name="cardUseDate"></label></dd>
			<dt class="giant">所属机构：</dt>
			<dd class="giant"><select name="agencyType" style="width:159px"></select></dd>
			<dt class="giant">所属单位：</dt>
			<dd class="giant"><select name="unitCode"><option value="">-请选择-</option></select></dd>
			<div class="cl"></div>
		</dl>
		</form>
	</div>
	<script type="text/javascript">
	var vCode = function(obj){
		var ver = $(obj).attr('ver');
		var msg = $(obj).attr('msg');
		var val = $(obj).val();
		var code = ver.substr(1);
			code = code.substr(0,code.length-1);
		var exp = new RegExp(code);
		
		var num = val.substr(1);
		if(num.length < 6){
			var n = 6 - num.length;
			for(i=0;i<n;i++){
				num = '0'+num;
			}
			val = val.substr(0,1)+num;
		}
		
		if($.type(exp) === 'regexp'){
			if(!exp.test(val)){
				$.dialog.alert(msg);
				$(obj).focus();
				$(obj).val('C');
			}else{
				$(obj).val(val.toUpperCase())
			}
		}
	}
	$(function(){
		$(document.search).ajaxForm({
			beforeSubmit:function(formData){
				var param = $(formData).formParam();
				$('#list').page('param',param);
				$('#list').page('show');
				return false;
			}
		});
		$(document.addForm).ajaxForm({
			beforeSubmit:function(form){
				var ver = $(document.addForm).validator();
				if(!ver.reg) $.dialog.alert(ver.msg);
				return ver.reg;
			},
			success:function(response){
				if(response == '1'){
					var param = $(document.search).formParam();
					$('#list').page('param',param);
					$('#list').page('show');
					$.dialog.list['viewdialoga'].close();
				}else{
					$.dialog.alert('保存失败，设备号已存在！')
				}
			}
		});
		$(document.updForm).ajaxForm({
			success:function(response){
				var param = $(document.search).formParam();
				$('#list').page('param',param);
				$('#list').page('show');
			}
		});
		//分页列表
		$('#list').page({
			url:'jbxxwh_search.action',
			config:'pageinfo,record,first,last,next,prev,jump',
			items:[{
				name:'indexId',
				type:'checkbox',
				width:13
			},{
				title:'设备号',
				name:'cardNumber'
			},{
				title:'用途',
				name:'cardUseText'
			},{
				title:'所属单位',
				name:'unitCode',
				irender:function(row){
					if(row.adminName!=null){
						return row.adminName;
					}
					if(row.propertyName!=null){
						return row.propertyName;
					}
					if(row.serviceName!=null){
						return row.serviceName;
					}
				}
			},{
				title:'启用时间',
				name:'cardUseDate'
			},{
				title:'详情',
				render:function(row){
					$a = $('<a href="javascript:void(0)">【详细】</a>');
					$a.click(function(){
						updView(row);
					});
					return $a;
				}
			}]
		});
		$('#btnAdd').click(function(){
			addView(null);
		});
		$('#btnDel').click(function(){
			$.dialog.confirm('您确认删除所选电梯吗？',function(){
				var ids = $('#list').data('checked').join(',');
				$.post('jbxxwh_del.action',{ids:ids},function(response){
					$('#list').page('show',1);
				});
			});
		});
	});

	$(function(){
		//绑定行政监管单位
		$('select[name=cardUse]').selectload('../../common/code.action','code','codedesc',{codepid:'50'});
		$('select[name=agencyType]').selectload('../../common/code.action','code','codedesc',{codepid:'64'});
		$('select[name=agencyType]').change(function(){
			switch (this.value) {
				case '1':
					$('select[name=unitCode]').selectload('../../common/adminunit_select.action','adminCode','adminName');
					break;
				case '2':
					$('select[name=unitCode]').selectload('../../common/propertyunit_select.action','propertyCode','propertyName');
					break;
				case '3':
					$('select[name=unitCode]').selectload('../../common/serviceunit_select.action','serviceCode','serviceName');
					break;
				default:
					$('select[name=unitCode]').html('<option value="">-请选择-</option>')
					break;
			}
		});
	})
	
	var addView = function(row){
		$(document.addForm).resetForm();
		$.dialog({
			id:'viewdialoga',
			title:'信息添加-基本信息维护',
			lock:true,
			width:'100%',
			height:'100%',
			padding:'5px 8px 5px 5px',
			content:document.getElementById('addview'),
			button:[{
				name:"保存",
				focus:true,
				callback:function(){
					$(document.addForm).submit();
					return false;
				}
			}]
		});
	}
	var updView = function(row){
		$(document.updForm).resetForm();
		$(document.updForm.indexId).val('');
		$.dialog({
			id:'viewdialogu',
			title:'信息查看-基本信息维护',
			lock:true,
			width:'100%',
			height:'100%',
			padding:'5px 8px 5px 5px',
			content:document.getElementById('updview'),
			button:[{
				name:"保存",
				focus:true,
				callback:function(){
					$(document.updForm).submit();
				}
			}]
		});
		switch (row.agencyType) {
			case '1':
				$('select[name=unitCode]').selectload('../../common/adminunit_select.action','adminCode','adminName',null,false);
				break;
			case '2':
				$('select[name=unitCode]').selectload('../../common/propertyunit_select.action','propertyCode','propertyName',null,false);
				break;
			case '3':
				$('select[name=unitCode]').selectload('../../common/serviceunit_select.action','serviceCode','serviceName',null,false);
				break;
			default:
				$('select[name=unitCode]').html('<option value="">-请选择-</option>')
				break;
		}
		$(document.updForm).json2form(row);
	}
	</script>
</body>
</html>
